package com.troila.cloud.simplify.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.troila.cloud.simplify.model.WechatMediaAccount;
import com.troila.cloud.simplify.repository.WechatMediaAccountRepository;

@Service
@Transactional
public class WechatMediaAccountService {
	
	@Autowired
	private WechatMediaAccountRepository wechatMediaAccountRepository;
	
	public void save(WechatMediaAccount wechatMediaAccount,int status) {
		//查询是否存在
		WechatMediaAccount wechatMediaAccountOld = wechatMediaAccountRepository.findByMediaKey(wechatMediaAccount.getMediaKey());
		if(wechatMediaAccountOld == null) {
			wechatMediaAccountOld = wechatMediaAccount;
			wechatMediaAccountOld.setGmtCreate(new Date());
		}
			
		wechatMediaAccountOld.setGmtUpdate(new Date());
		wechatMediaAccountOld.setStatus(status);
		wechatMediaAccountRepository.save(wechatMediaAccountOld);
		
		
	}

}